{%extends "base.html"%}

{%block scripts%}
		<script type="text/javascript">
			$(document).ready(function(){
				$("#sp_select").change(function () {
					$("#config_div").text("Loading...");
	          		var str = "";
					$("#sp_select option:selected").each(function () {
					    str += $(this).text() + " ";
					    //alert(str);
						$.ajax({
						    url: '/config/getconfig'  ,
						    type: 'GET',
						    data: "sp="+$(this).text(),
						    timeout: 5000,
						    error: function(){
						        alert('加载页面失败！');
								$("#config_div").html('加载页面失败！');
						    },
						    success: function(html){
								$("#config_div").html(html);
						    }
						});
					});
				})
				.change();
			});// $(document).ready(function()
		</script>
{%endblock%}

{%block content%}
	<div id="middle_account_div">
	    <h1>同步帐号设置</h1>

	    <div class="middle_account_item_div">
	        <h2>配置页面说明</h2>
	        <p>在这里 我们可以配置微博调谐器</p>
	    </div>
	    <div class="middle_account_item_div">
			<h2>{%ifequal operation 1%}添加新项目{%endifequal%}{%ifequal operation 2%}编辑项目{%endifequal%}</h2>
	        <div class="middle_account_div">
	            <label>服务提供商：</label>
	            <div class="middle_account_content_div">
					<form name = "form1" action="/config/desti/addnew" method="post">
					<div><!--服务提供商：--><select id = "sp_select" class="" name="serviceprovider">{{ updaters }}</select>
					<div><!--配置：--><br/><ol><div id = "config_div"/> </ol></div>
					</form>
	            </div>
	            <div class="middle_account_item_button_div">
	                <a class="middle_button_div" type="password" href=""  id = "summitlink" > 提交 </a>
	            </div>
	            <div class="hr">
	                <hr />
	            </div>
	        </div>
	        <script>
				$("#summitlink").click(function () {
	          		var str = "";
					$("#config_div input:text").each(function () {
					    str = str + "'" + $(this).attr('name') + "':'" + $(this).attr('value') + "',"
					});
					str = '{'+ str + '}';
					$("#sp_select option:selected").each(function () {
					    sp = $(this).text();
					});
					$.post('/config/desti/addnew', {
					    serviceprovider : sp,
					    config: str,
						}, function() {
					    alert('您提交的信息已经保存');
					});
				}); // $("#summitlink").click(function ()
	        </script>
	        <div class="hr">
	            <hr />
	        </div>
	    </div>
		{%ifequal operation 1%}
			{%for item in desti%}
			<div class="middle_account_item_div">
				<div class="middle_account_div">
					<div class="middle_account_content_div">
						<h2>服务提供商：	<select id = "sp_select_{{ item.id }}" class="" name="serviceprovider">{{ item.updaters }}</select></h2>
					</div>
					<script>
						$("#sp_select_{{ item.id }}").change(function () {
							//alert("changed!")
						});
					</script>
		            <div class="hr">
		                <hr />
		            </div>
					<p>在这里我们可以填写或者修改想要同步到的微博客的登录信息</p>
					<div class="middle_account_div">
						<label>用户</label>{{ item.user }}<br/>
						<label>服务提供商</label>{{ item.serviceprovider }} <br/>
						<label>配置</label>{{ item.config_page }} <br/>
						<label>设置时间</label>{{ item.create_time }} <br/>
						<div class="middle_account_item_button_div">
							<a class="middle_button_div" href="/config/desti/edit/%s"> 编辑 </a>
						</div>
						<div class="middle_account_item_button_div">
							<a class="middle_button_div" href="/config/desti/delete?timestamp={{ item.create_time }}"> 删除 </a>
						</div>
					</div>
				</div>
	            <div class="hr">
	                <hr />
	            </div>
			</div>
			<br/>
			{%endfor%}
		{%endifequal%}
	</div>
{%endblock%}

